namespace RuoVea.WeighIns.Web.Controllers;

/// <summary>
/// 
/// </summary>
[Authorize(Roles = "None")]
public partial class WeighInfoController : Controller
{
    /// <summary>
    /// 
    /// </summary>
    private readonly WeighInfoService _weighInfoService;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="thisRepository"></param>
    /// <param name="currentUser"></param>
    public WeighInfoController(WeighInfoService weighInfoService)
    {
        _weighInfoService = weighInfoService;
    }

    public IActionResult Index()
    {
        ViewBag.Title = "体重记录管理";
        return View();
    }

    public IActionResult Dashboard()
    {
        ViewBag.Title = "体重数据分析";
        return View();
    }

    public IActionResult QuickRecord()
    {
        ViewBag.Title = "快速记录体重";
        return View();
    }

    public IActionResult BatchRecord()
    {
        ViewBag.Title = "批量记录体重";
        return View();
    }

    public IActionResult TrendAnalysis()
    {
        ViewBag.Title = "体重趋势分析";
        return View();
    }

    public IActionResult StatAnalysis()
    {
        ViewBag.Title = "体重统计分析";
        return View();
    }

    public IActionResult MetricsRecord()
    {
        ViewBag.Title = "身体指标记录";
        return View();
    }

    public async Task<RestfulResult<List<InsMeridiem>>> GetMeridiemList()
    {
        return await _weighInfoService.GetMeridiemListAsync();
    }

    /// <summary>
    /// 查询所有/分页
    /// </summary>
    /// <param name="page"></param>
    /// <returns></returns>
    [HttpPost("WeighInfo/pages")]
    public async Task<RestfulResult<PageResult<InsWeighInfoDto>>> GetPagesAsync([FromBody] WeighInfoPageParam page)
    {
        return await _weighInfoService.GetPagesAsync(page);
    }

    /// <summary>
    /// 获取体重记录详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("WeighInfo/detail/{id}")]
    public async Task<RestfulResult<InsWeighInfo>> GetDetailAsync(long id)
    {
        return await _weighInfoService.GetDetailAsync(id);
    }

    /// <summary>
    /// 获取体重趋势数据
    /// </summary>
    /// <param name="days">查询天数</param>
    /// <returns></returns>
    [HttpGet("WeighInfo/trend/{days?}")]
    public async Task<RestfulResult<List<WeightTrendPoint>>> GetWeightTrendAsync(int days = 30)
    {
        return await _weighInfoService.GetWeightTrendAsync(days);
    }

    /// <summary>
    /// 获取体重统计数据
    /// </summary>
    /// <returns></returns>
    [HttpGet("WeighInfo/stat")]
    public async Task<RestfulResult<WeightStatViewModel>> GetWeightStatAsync()
    {
        return await _weighInfoService.GetWeightStatAsync();
    }

    /// <summary>
    /// 获取时段字典数据
    /// </summary>
    /// <returns></returns>
    [HttpGet("WeighInfo/meridiem/list")]
    public async Task<RestfulResult<List<InsMeridiem>>> GetMeridiemListAsync()
    {
        return await _weighInfoService.GetMeridiemListAsync();
    }

    /// <summary>
    /// 批量添加体重记录
    /// </summary>
    /// <param name="records"></param>
    /// <returns></returns>
    [HttpPost("WeighInfo/batchAdd")]
    [UnitOfWork]
    public async Task<RestfulResult> BatchAddAsync([FromBody] List<InsWeighInfoDto> records)
    {
        return await _weighInfoService.BatchAddAsync(records);
    }

    /// <summary>
    /// 增加
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [UnitOfWork]
    [HttpPost("WeighInfo/add")]
    public async Task<RestfulResult> AddAsync([FromBody] InsWeighInfoDto data)
    {
        return await _weighInfoService.AddAsync(data);
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpPost("WeighInfo/update")]
    public async Task<RestfulResult> UpdateAsync([FromBody] InsWeighInfoDto data)
    {
        return await _weighInfoService.UpdateAsync(data);
    }

    /// <summary>
    /// 快速记录体重
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [UnitOfWork]
    [HttpPost("WeighInfo/QuickRecord")]
    public async Task<RestfulResult> QuickRecordAsync([FromBody] InsWeighInfoDto data)
    {
        return await _weighInfoService.AddAsync(data);
    }



    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    [HttpDelete("WeighInfo/delete")]
    public async Task<RestfulResult> DeleteAsync([FromBody] EntityBaseId data)
    {
        return await _weighInfoService.DeleteAsync(data);
    }
}